package com.acwing.partition36;

import java.io.*;

/**
 * @author rkc
 * @date 2022/7/19 9:31
 */
public class AC3587连通图 {

    private static final int N = 1010;
    private static int[] parent = new int[N];
    private static int n, m;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        while (true) {
            String s = reader.readLine();
            if (s == null || s.isEmpty()) break;
            String[] ss = s.split(" ");
            n = Integer.parseInt(ss[0]); m = Integer.parseInt(ss[1]);
            for (int i = 1; i <= n; i++) parent[i] = i;
            for (int i = 0; i < m; i++) {
                ss = reader.readLine().split(" ");
                int x = Integer.parseInt(ss[0]), y = Integer.parseInt(ss[1]), fa = find(x), fb = find(y);
                if (fa != fb) parent[fa] = fb;
            }
            int root = find(1);
            boolean flag = true;
            for (int i = 2; i <= n; i++) {
                if (find(i) != root) {
                    flag = false;
                    break;
                }
            }
            writer.write(flag ? "YES\n" : "NO\n");
        }
        writer.flush();
    }

    private static int find(int x) {
        if (x != parent[x]) parent[x] = find(parent[x]);
        return parent[x];
    }
}
